package com.mzw.huaxiarealestatebackend.controller;


import com.mzw.huaxiarealestatebackend.common.utils.DataResult;
import com.mzw.huaxiarealestatebackend.entity.PanFile;
import com.mzw.huaxiarealestatebackend.service.PanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@Api(tags = "网盘")
@RequestMapping("/api/pan")
@RestController
public class PanController {
    @Autowired
    PanService panService;
    @ApiOperation("创建项目")
    @GetMapping("/createProject")
    DataResult  createProject(@RequestParam String pjtNo) {
        Map<String, String> result = panService.createDirectoryStructure(pjtNo);
        return DataResult.ok(result);
    }
    @ApiOperation("获取数据")
    @GetMapping("/getData")
    List<PanFile> getData(@RequestParam Map<String, String> map) {
        return panService.getFile(map);
    }
    @ApiOperation("上传文件")
    @PostMapping("/uploadFile")
    DataResult uploadFile(@RequestPart("files") List<MultipartFile> files, @RequestParam Map<String, String> map) {
        ResponseEntity<String> responseEntity = panService.uploadFile(files, map);
        return DataResult.ok(responseEntity);
    }
    @ApiOperation("判断文件是否能上传")
    @GetMapping("/determineUpload")
    DataResult couldUpload(@RequestParam Map<String, String> map) {
        Boolean result = panService.couldUpload(map);
        if(result)
            return DataResult.ok();
        else
            return DataResult.failure();
    }
    @ApiOperation("批量下载文件")
    @GetMapping("/download")
    ResponseEntity<byte[]> downloadFile(@RequestParam Map<String, String> map) {
        System.out.println(panService.downloadFile(map));
        return panService.downloadFile(map);
    }
    @ApiOperation("删除文件")
    @GetMapping("/delete")
    Map<String, String> deleteFile(@RequestParam Map<String,String> map) {
        return panService.deleteFile(map);
    }
}
